package com.quanquan.resource.repository;

import com.quanquan.resource.entity.Image;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 功能描述:
 *
 * @ClassName: imageRepository
 * @Author: xiaoqianh丶
 * @Date: 2019-03-12 15:32
 * @Version: V1.0
 */
@Transactional
public interface imageRepository  extends JpaRepository<Image, String> {

    @Query(value="select * from oo_image where foreign_key_id =?1 and status_remove= 0" ,nativeQuery=true)
    public List<Image> findImagesByForeignKeyId(String foreignKeyId);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value="update oo_image set status_remove= 1 where foreign_key_id =?1" ,nativeQuery=true)
    public void removeShip(String foreignKeyId);


    /**
     * 检查是否是啥操作（更新还是新增）
     * @return
     */
    public List<Image> findImagesByForeignKeyIdAndRemove(String foreignKeyId ,Integer remove);

    /**
     * 根据图片的属性和图片的状态来查询图片
     * @param belong
     * @param remove
     * @return
     */
    public Image findImageByBelongAndRemove(String belong, Integer remove);

}
